package com.ykan.ykds.ctrl.utils;

import android.content.Context;
import android.util.Log;

public class Ciphertext {
	
	private static Ciphertext ciphertext;
	
	public native static String decode(String cmd);
	
	public native static String encode(String cmd);
	
	public static native int init(Context ctx);
	
	private Context ctx;
	
	private Ciphertext(Context ctx){
		this.ctx = ctx;
		init(ctx);
	}
	
	public static Ciphertext getInstance(Context ctx){
		if(ciphertext == null){
			ciphertext = new Ciphertext(ctx);
		}
		return ciphertext;
	}
	
	public static Ciphertext getInstance(){
		if(ciphertext == null){
			Log.e(Ciphertext.class.getSimpleName(), "ciphertext is null");
		}
		return ciphertext;
	}
	
	//加密
	public  String e(String str){
		return encode(str);
	}
	
	//解密
	public static String d(String str){
		return decode(str);
	}
	
	static{
		System.loadLibrary("ykancipher");
	}
}
